<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>


<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <!-- Title and other stuffs -->
    <title>添加新闻信息</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <jsp:include page="../commons/css.jsp"></jsp:include>
</head>
<body>
<!-- 头部 -->

<jsp:include page="../commons/head.jsp"></jsp:include>

<div class="content">

    <!-- 左边菜单 -->

    <jsp:include page="../commons/left.jsp"></jsp:include>

    <!-- 内容 -->
    <div class="mainbar">
        <div class="page-head">
            <h2 class="pull-left"><i class="icon-home"></i> 首页</h2>
            <div class="bread-crumb pull-right">
                <a href="index.html"><i class="icon-home"></i> 首页</a>
                <span class="divider">/</span>
                <a href="#" class="bread-current">控制台</a>
            </div>
            <div class="clearfix"></div>
        </div>

        <!-- Matter -->
        <div class="matter">
            <div class="container">

                <div class="row">
                    <div class="col-md-12">

                        <div class="widget wgreen">

                            <div class="widget-head">
                                <div class="pull-left">添加新闻信息</div>
                                <div class="clearfix"></div>
                            </div>

                            <div class="widget-content">
                                <div class="padd">

                                    <!-- Form starts.  -->
                                    <form class="form-horizontal" role="form" method="post" action="#">
                                        <div class="form-group text-center">

                                        </div>

                                        <div class="form-group">
                                            <label class="col-lg-4 col-md-4 col-xs-4 control-label">标题</label>
                                            <div class="col-lg-8 col-md-8 col-xs-8">
                                                <input id="title" name="title" type="title" required="required" value=""
                                                       class="form-control" placeholder="标题">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-4 col-md-4 col-xs-4 control-label">记者</label>
                                            <div class="col-lg-8 col-md-8 col-xs-8">
                                                <input id="reporter" name="reporter" type="reporter" required="required"
                                                       class="form-control" placeholder="记者">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-4 col-md-4 col-xs-4 control-label">发布时间</label>
                                            <div class="col-lg-8 col-md-8 col-xs-8">
                                                <input id="release_time" name="release_time" required="required"
                                                       type="date" class="form-control" placeholder="发布时间">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-4 col-md-4 col-xs-4 control-label">修改时间</label>
                                            <div class="col-lg-8 col-md-8 col-xs-8">
                                                <input id="update_time" name="update_time" required="required"
                                                       type="date" class="form-control" placeholder="修改时间">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-4 col-md-4 col-xs-4 control-label">新闻内容</label>
                                            <div class="col-lg-8 col-md-8 col-xs-8">
                                                <input id="content" name="content" required="required" type="content"
                                                       class="form-control" placeholder="新闻内容">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-4 col-md-4 col-xs-4 control-label">新闻关键字</label>
                                            <div class="col-lg-8 col-md-8 col-xs-8">
                                                <input id="key_words" name="key_words" required="required"
                                                       type="key_words" class="form-control" placeholder="新闻关键字">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-4 col-md-4 col-xs-4 control-label">新闻类别</label>
                                            <div class="col-lg-8 col-md-8 col-xs-8">
                                                <input id="category_id" name="category_id" required="required"
                                                       type="category_id" class="form-control" placeholder="新闻类别">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <div class="col-lg-offset-1 col-lg-1 col-md-offset-1 col-md-1 col-xs-5">
                                                <button type="button" class="btn btn-success" onclick="add()">确认添加
                                                </button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="clearfix"></div>
</div>

<!-- 底部 -->
<jsp:include page="../commons/foot.jsp"></jsp:include>

<!-- 快速回到顶部 -->
<span class="totop"><a href="#"><i class="icon-chevron-up"></i></a></span>

<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">消息提示框</h4>
            </div>
            <div class="modal-body">添加成功</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
<!-- /.modal -->
</body>
<script type="text/javascript">
    function add() {
        var release_time = $("#release_time").val()
        var update_time = $("#update_time").val()
        var content = $("#content").val()
        var key_words = $("#key_words").val()
        var category_id = $("#category_id").val()
        if ($("#title").val() == "") {
            alert("标题不能为空!");
            return false;//阻止表单提交，取消submit事件
        } else if ($("#reporter").val() == "") {
            alert("发布人不能为空!");
        } else {

            //ajax实现添加账号
            $.ajax({
                type: "post",
                url: "insertNews",
                async: false,
                data: {
                    "title": $("#title").val(),
                    "reporter": $("#reporter").val(),
                    "release_time": release_time,
                    "update_time": update_time,
                    "content": content,
                    "key_words": key_words,
                    "category_id": category_id
                },
                success: function (data) {
                    if (data == "success") {
                        $(".modal-body").text("添加成功");
                        //显示模态框
                        $('#myModal').modal('show')
                    } else {
                        $(".modal-body").text("添加失败");
                        //显示模态框
                        $('#myModal').modal('show')
                    }
                },
                error: function () {
                    $(".modal-body").text("添加失败");
                    //显示模态框
                    $('#myModal').modal('show')
                }

            });

        }
    }

</script>

</html>